<%@ page language="java" import="java.util.*" pageEncoding="utf-8"%>
<%@ include file="/common/taglibs.jsp"%>
<html>
	<head>
		<base href="<%=basePath%>">
		<title>添加角色</title>
		<meta http-equiv="pragma" content="no-cache">
		<meta http-equiv="cache-control" content="no-cache">
		<meta http-equiv="expires" content="0">
		<meta http-equiv="keywords" content="keyword1,keyword2,keyword3">
		<meta http-equiv="description" content="This is my page">
		<script type="text/javascript" src="${ctx }/js/checkdtree/wtree.js"></script>
		<link href="${ctx }/js/checkdtree/dtree.css" rel="stylesheet" type="text/css"></link>
		<script type="text/javascript" >
		   
		   var result = "${result}";
  		   if(result=='1'){
  		 		alert("保存成功！");
  		        document.location.href ='${ctx}/pages/role/list.action';
  		   }
  
		   function subForm(){
		   		var roleId="${role.id}";
		   		var ids = ""; 
		   		$(":checkbox").each(function (){
					if($(this).is(":checked")){
						ids = ids + $(this).val()+",";
					}		   		
		   		});
		   		
		   		$.ajax({ 
				    type: "POST",
					url: "${ctx}/pages/role/updateRoleRes.action",
					data:{'id':roleId,'ids':ids},
					dataType:"text",
					success: function(data){
	     		 		if(data==1){
	     		 			alert("保存成功");
	     		 			window.location.reload(); 
	     		 		}
	     		 	}
	     		 });
		   		$("#roleForm").submit();
		   }
		</script>
	</head>
	<body>
	<div id="body-wrapper">
		<div id="main-content">
			<div class="content-box">
				<!-- Start Content Box -->
				<div class="content-box-header">
					<h3 style="cursor: s-resize;">
						授权管理 <span style="color: red;"> (${role.name }) </span>
					</h3>
					<div class="clear"></div>
				</div>
				<!-- End .content-box-header -->
				<div style="display: block;"  class="content-box-content">
					<div id="dtree" ></div>
					<div class="clear"></div>
					<p></p><p></p>
					<input class="button" value="保存" onclick="subForm();"  type="button">
					<input class="button" value="返回" onclick="history.back();"  type="button">
				</div>
				
			</div>
		</div>
		</div>
	</body>
	<script type="text/javascript">
		var d = new dTree('d','${ctx }/js/checkdtree/images/system/menu/');
		d.config.folderLinks=true;
		d.config.useCookies=false;
		d.config.check=true;
		
		d.add(0,-1,'系统菜单',"javascript:;",'提示');
		<c:forEach items="${resAllList}" var="res">
			d.add(${res.id },${res.parentID },'${res.name}',"javascript:;",'所有系统管理功能');
		</c:forEach>
		
		document.getElementById('dtree').innerHTML = d;
		d.openAll();
		
		<c:forEach items="${resIdList}" var="roleRes">
			d.co('${roleRes}').checked=true;
		</c:forEach>
	</script>
</html>
